package com.itheima.test;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.util.List;

public class 分页 {
    @Test
    public void testPage() throws Exception{
        SqlSession sqlSession = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("UserMapper.xml")).openSession();

        PageHelper.startPage(1,2);

        UserDao userDao = sqlSession.getMapper(UserDao.class);

        List<User> all = userDao.findAll();

        sqlSession.close();

        PageInfo<User> p1 = new PageInfo<>(all);
        System.out.println("总页数:"+p1.getPages());
        System.out.println("总记录数"+p1.getTotal());
        System.out.println("每页显示条数:"+p1.getPageSize());
        System.out.println("当前第:"+p1.getPageNum()+"页");
    }
}
